package com.fjnu.config;


import com.fjnu.teaching.Teacher;
import com.fjnu.teaching.TeachingDao;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.sql.Connection;
import java.sql.DriverManager;

@Configuration
@ComponentScan(basePackages = "com.fjnu.teaching")
@PropertySource("db.properties")
public class SpringIocConfig {


    @Value("${mysql.driver}")
    private String driver ;
    @Value("${mysql.url}")
    private String url ;
    @Value("${mysql.user}")
    private String user ;
    @Value("${mysql.password}")
    private String password ;




    public Connection connection() {
        try {
            Class.forName(driver) ;
            return DriverManager.getConnection(url, user, password) ;

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null ;
    }

    @Bean
    public Teacher getTeacher() {
        System.out.println("the method getTeacher was called.") ;
        return new Teacher() ;
    }

    @Bean
    public TeachingDao getTeachingDao() {
        return new TeachingDao() ;
    }




}
